﻿using System.Windows.Interactivity;
using System.Windows.Controls;
using System.Collections.ObjectModel;
using System.Linq;
using BotModels;
namespace AllBots.Behaviour
{
    public class ScrollDownBehavior : TriggerAction<ListBox>
    {
        protected override void Invoke(object parameter)
        {
            var source = (ObservableCollection<Message>)AssociatedObject.ItemsSource;
            source.CollectionChanged += (s, e) =>
            {
                if (AssociatedObject.Items.Count > 0)
                {
                    AssociatedObject.ScrollIntoView(
                        AssociatedObject.Items.Last());
                }
            };
        }
    }
}
